package com.ty.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ty.skysystem.entity.UserEntity;
import com.ty.skysystem.service.UserService;
import com.ty.common.utils.PageUtils;
import com.ty.common.utils.R;

/**
 * 系统用户表: 用于存放用户账户密码信息及用户信息 字段名: role_id => 对应表: role
 *
 * @author tianyuzhu
 * @email 1659770218@QQ.COM
 * @date 2020-12-11 16:03:39
 */
@RestController
@RequestMapping("user")
public class UserController {
  @Autowired private UserService userService;

  /** 列表 */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = userService.queryPage(params);

    return R.ok().put(page);
  }

  /** 信息 */
  @RequestMapping("/info/{userId}")
  public R info(@PathVariable("userId") Long userId) {
    UserEntity user = userService.getById(userId);

    return R.ok().put(user);
  }

  /** 保存 */
  @RequestMapping("/save")
  public R save(@RequestBody UserEntity user) {
    userService.save(user);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  public R update(@RequestBody UserEntity user) {
    userService.updateById(user);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] userIds) {
    userService.removeByIds(Arrays.asList(userIds));

    return R.ok();
  }
}
